package net.zoneland.knowledge.config;

import net.zoneland.knowledge.utils.ElasticSearchPoolUtil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * .
 *
 * @author: bcc
 * 2021/5/21
 */
@Configuration
@ConfigurationProperties(prefix = "es")
public class EsConfig implements InitializingBean, EsConfigInterface {

    private String schema = "http";

    private String isSecureMode = "false";

    private String principal = "none";

    private String serverHost;

    private String indexName = "knowledgedb";

    private String chatIndexName = "aitalk_chat";

    private int querySize = 100;

    private int maxRetryTimeoutMillis = 5000;

    private int connectTimeout = 5000;

    private int socketTimeout = 5000;

    private int connectionRequestTimeout = 3000;

    private int maxConnPerRoute = 100;

    private int maxConnTotal = 1000;

    private String password;

    /**
     * .
     *
     * @return schema
     */
    @Override
    public String getSchema() {
        return schema;
    }

    /**
     * .
     *
     * @param schema to set
     */
    public void setSchema(final String schema) {
        this.schema = schema;
    }

    /**
     * .
     *
     * @return isSecureMode
     */
    @Override
    public String getIsSecureMode() {
        return isSecureMode;
    }

    /**
     * .
     *
     * @param isSecureMode to set
     */
    public void setIsSecureMode(final String isSecureMode) {
        this.isSecureMode = isSecureMode;
    }

    /**
     * .
     *
     * @return principal
     */
    @Override
    public String getPrincipal() {
        return principal;
    }

    /**
     * .
     *
     * @param principal to set
     */
    public void setPrincipal(final String principal) {
        this.principal = principal;
    }

    /**
     * .
     *
     * @return serverHost
     */
    @Override
    public String getServerHost() {
        return serverHost;
    }

    /**
     * .
     *
     * @param serverHost to set
     */
    public void setServerHost(final String serverHost) {
        this.serverHost = serverHost;
    }

    /**
     * .
     *
     * @return indexName
     */
    @Override
    public String getIndexName() {
        return indexName;
    }

    /**
     * .
     *
     * @param indexName to set
     */
    public void setIndexName(final String indexName) {
        this.indexName = indexName;
    }

    /**
     * .
     *
     * @return chatIndexName
     */
    @Override
    public String getChatIndexName() {

        return chatIndexName;
    }

    /**
     * .
     *
     * @param chatIndexName to set
     */
    public void setChatIndexName(final String chatIndexName) {

        this.chatIndexName = chatIndexName;
    }

    /**
     * .
     *
     * @return querySize
     */
    @Override
    public int getQuerySize() {
        return querySize;
    }

    /**
     * .
     *
     * @param querySize to set
     */
    public void setQuerySize(final int querySize) {
        this.querySize = querySize;
    }

    /**
     * .
     *
     * @return maxRetryTimeoutMillis
     */
    @Override
    public int getMaxRetryTimeoutMillis() {
        return maxRetryTimeoutMillis;
    }

    /**
     * .
     *
     * @param maxRetryTimeoutMillis to set
     */
    public void setMaxRetryTimeoutMillis(final int maxRetryTimeoutMillis) {
        this.maxRetryTimeoutMillis = maxRetryTimeoutMillis;
    }

    /**
     * .
     *
     * @return connectTimeout
     */
    @Override
    public int getConnectTimeout() {
        return connectTimeout;
    }

    /**
     * .
     *
     * @param connectTimeout to set
     */
    public void setConnectTimeout(final int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    /**
     * .
     *
     * @return socketTimeout
     */
    @Override
    public int getSocketTimeout() {
        return socketTimeout;
    }

    /**
     * .
     *
     * @param socketTimeout to set
     */
    public void setSocketTimeout(final int socketTimeout) {
        this.socketTimeout = socketTimeout;
    }

    /**
     * .
     *
     * @return connectionRequestTimeout
     */
    @Override
    public int getConnectionRequestTimeout() {
        return connectionRequestTimeout;
    }

    /**
     * .
     *
     * @param connectionRequestTimeout to set
     */
    public void setConnectionRequestTimeout(final int connectionRequestTimeout) {
        this.connectionRequestTimeout = connectionRequestTimeout;
    }

    /**
     * .
     *
     * @return maxConnPerRoute
     */
    @Override
    public int getMaxConnPerRoute() {
        return maxConnPerRoute;
    }

    /**
     * .
     *
     * @param maxConnPerRoute to set
     */
    public void setMaxConnPerRoute(final int maxConnPerRoute) {
        this.maxConnPerRoute = maxConnPerRoute;
    }

    /**
     * .
     *
     * @return maxConnTotal
     */
    @Override
    public int getMaxConnTotal() {
        return maxConnTotal;
    }

    /**
     * .
     *
     * @param maxConnTotal to set
     */
    public void setMaxConnTotal(final int maxConnTotal) {
        this.maxConnTotal = maxConnTotal;
    }

    /**
     * .
     *
     * @return password
     */
    @Override
    public String getPassword() {

        return password;
    }

    /**
     * .
     *
     * @param password to set
     */
    public void setPassword(final String password) {

        this.password = password;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        ElasticSearchPoolUtil.setEsConfig(this);
        ElasticSearchPoolUtil.initRestClientBuilder();
    }
}
